<?php
require ('checkFr.php');
if (isset($_POST['remember']) && empty($_COOKIE['pseudo']))
{
//si cookie vide 
	setcookie('pseudo', $_POST['login1'], time() + 3600*24*3, null, null, false, true); 
}
else if(isset($_POST['remember']) && !empty($_COOKIE['pseudo']))
{
// si cookie non vide
	setcookie('pseudo', '', 0, null, null, false, true); 
	setcookie('pseudo', $_POST['login1'], time() + 3600*24*3, null, null, false, true); 
}
if ($_SESSION['login1'] == NULL) {
    header('Location: authentifFr.php');
    }
else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
        <head>
				<meta charset="utf-8" />
                <link style rel="stylesheet" type="text/css" href="style.css">
				<h2><?php echo $_SESSION['login1']; ?></br> </br>
				<span>
				<a href="logoutFr.php"  >Deconnexion</a></h2></span>

				<form action="profileFr.php" method="post">
					<center><input type="submit" value="Editer mon profil" /></center><br><br>
				</form>     		
        </head>
		<body>
			
		<form action="#" method="post">
         <center>
			<table  id = "border" border="1" width=30%  height=300 border align ="center"   >
				<td id ="border1" valign="bottom"  width=20%  height=300 border align ="left">			
			 <div id="convers">
			<script> 
			String.prototype.nl2br = function()
			{
				return this.replace(/\n/g, "<br />");
			}
			function discuss()
					{
						$.ajax({
							url: "mess_sessionFr.txt",
							success: function(msg)
							{
								
								$("#convers").html(msg.nl2br());
							}
						});
					}
			</script>
			
			<?php	
				
				function writefile($fic_mess)
				{
				$handle = fopen($fic_mess,"a");
					if (!empty($_POST['message']) && isset($_POST['message']))
					{   	
						$date = date("d-m-Y");
						$heure = date("H:i");
						$message=$_POST['message'];
						fwrite ($handle,$date);
						fwrite ($handle," ");
						fwrite ($handle,$heure);
						fwrite ($handle," ");
						fwrite ($handle,$_SESSION['login1']);
						fwrite ($handle," a dit: ");
						fwrite ($handle,$_POST['message']);
						fwrite ($handle,"\r\n");
					?></div>
						<script src="jquery.js"></script>
						<script  charset="utf-8">
						setInterval("discuss()",1); </script>
									
						<?php
						fclose($handle);				
					} 
				}
				writefile( "mess_sessionFr.txt");
					?>
						
				</br></br>
				<label for="message"></label><textarea rows="3" name="message" id="message"  placeholder="Message ..."></textarea><br />
				<script >
				function SmileySmile(){document.getElementById('message').innerHTML += ':)';}function SmileyClin(){document.getElementById('message').innerHTML += ';)';}function SmileyLangue(){document.getElementById('message').innerHTML += ':p';}
				function SmileyRigole(){document.getElementById('message').innerHTML += ':d';}function SmileyHi(){document.getElementById('message').innerHTML += '^^';}function SmileyCoeur(){document.getElementById('message').innerHTML += '<3';}
				function bold(){ document.getElementById('message').style.fontWeight='bold';} function italics(){ document.getElementById('message').style.fontStyle='italic';} function strike(){ document.getElementById('message').style.textDecoration="line-through";}
				function underlined(){ document.getElementById('message').style.textDecoration = 'underline';} function normal(){ document.getElementById('message').style.fontWeight  = 'normal';}
				function red(){document.getElementById('message').style.color = 'red'};function green(){document.getElementById('message').style.color = 'green'}; function blue(){document.getElementById('message').style.color = 'blue'};
				function black(){document.getElementById('message').style.color = 'black'};function jaune(){document.getElementById('message').style.color = 'yellow'};function pink(){document.getElementById('message').style.color = 'pink'};
				</script>
					<div id="SmMsg" style="visibility:hidden;" ></div>
					<div id="smiley">
					<a onClick="javascript:SmileySmile()"><img src="./image/sourire.png" /></a>
					<a onClick="javascript:SmileyClin()"><img src="./image/clin.png" /></a>
					<a onClick="javascript:SmileyLangue()"><img src="./image/langue.png" /></a>
					<a onclick="javascript:SmileyRigole()"><img src="./image/rigole.png" /></a>
					<a onClick="javascript:SmileyHi()"><img src="./image/hihi.png" /></a>
					<a onclick="javascript:SmileyCoeur()"><img src="./image/coeur.png" /></a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
					<a onclick="javascript:normal()">N</a>&nbsp&nbsp
					<a onclick="javascript:bold()"><b>G</b></a>&nbsp&nbsp
					<a onclick="javascript:italics()"><I>I</I></a>&nbsp&nbsp
					<a onclick="javascript:strike()"><strike>B</strike></a>&nbsp&nbsp
					<a onclick="javascript:underlined()"><u>S</u></a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
					<a onclick="javascript:red()"><img src="./image/rouge.gif" /></a>&nbsp&nbsp
					<a onclick="javascript:green()"><img src="./image/carrevert.jpg" /></a>&nbsp&nbsp
					<a onclick="javascript:blue()"><img src="./image/carre_bleu.gif" /></a>&nbsp&nbsp
					<a onclick="javascript:black()"><img src="./image/noir.jpg" /></a>&nbsp&nbsp
					<a onclick="javascript:jaune()"><img src="./image/jaune.jpg" /></a>&nbsp&nbsp
					<a onclick="javascript:pink()"><img src="./image/pink.png" /></a>&nbsp&nbsp
				</br></br>
				
				<input type="submit" onClick="post(), clear()" value="Send"  />
				
				<td id ="border2" width=10%  height=300 border align ="left">
					 
					<span id="ad">Membres en ligne:<br/>
					<?php  
					function Members($fic_onl)
					{
						$fp = fopen($fic_onl,"r");
						if(filesize ($fic_onl)!=0) //On teste si le fichier est vide ou non
						{
							$contenu = fread ($fp, filesize ($fic_onl));
							$tableau = explode("\r\n", $contenu);
							foreach($tableau as $ligne)
							{
								if(!empty($ligne))
								{
									$login = $ligne;
									echo '<img src="./image/vert.png" />';
									echo $login.'<br/>';
								}
							}
						}
						
						fclose($fp);
					}
					Members("onlineFr.txt");
					?>
					</span>
					
				<div id="change_status">
					<form action="#" method="post">
			<select id="status" >
					<option value="#" selected>------</option>
					<option value="0"  >Disponible </option>
					<option value="1" >Occupe</option>
					<option value="2" >Indisponible</option>
					</select>

					</form>
				
				</div>
			 
				
		</center>  
	
	</form>
		</table>
        </body> 
<?php }	?>	
</html>